#include <iostream>
using namespace std;

int n;
int fibnum1, fibnum2, fibnum3;

int main()
{
    cin >> n;
    fibnum1 = 0, fibnum2 = 1, fibnum3 = 0;

    while (fibnum3 < n)
    {
        fibnum3 = fibnum1 + fibnum2;
        fibnum1 = fibnum2;
        fibnum2 = fibnum3;
    }

    cout << min(fibnum2 - n, (n - fibnum1)) << endl;
}
